﻿SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
GO
CREATE PROCEDURE bhp_Temp_ModStructure
AS
BEGIN

	DECLARE
		@ViewFactoryId			INT,
		@PostListModelId		INT,
		@PostModelId				INT,
		@BlogSettingsId			INT

	SELECT @BlogSettingsId = id FROM n_Tree t WHERE t.name = 'BLOG_SETTINGS' AND parent = 0

	
	EXEC [dbo].[n_TableAdd] 'SYS_BLOG_VIEWFACTORIES', 9999999
		SELECT @ViewFactoryId = id FROM n_Tree t WHERE t.name = 'SYS_BLOG_VIEWFACTORIES'
	EXEC [dbo].[n_TableAdd] 'SYS_BLOG_POSTLISTMODEL', 9999999
		SELECT @PostListModelId = id FROM n_Tree t WHERE t.name = 'SYS_BLOG_POSTLISTMODEL'
	EXEC [dbo].[n_TableAdd] 'SYS_BLOG_POSTMODEL', 9999999
		SELECT @PostModelId = id FROM n_Tree t WHERE t.name = 'SYS_BLOG_POSTMODEL'

	INSERT INTO bht_Groups (Id, Name, [ReadOnly]) VALUES (@ViewFactoryId, 'SYS_BLOG_VIEWFACTORIES', 1)
	INSERT INTO bht_Groups (Id, Name, [ReadOnly]) VALUES (@PostListModelId, 'SYS_BLOG_POSTLISTMODEL', 1)
	INSERT INTO bht_Groups (Id, Name, [ReadOnly]) VALUES (@PostModelId, 'SYS_BLOG_POSTMODEL', 1)

	EXEC [dbo].[n_ColFAdd] @rel = @ViewFactoryId, @name = N'klucz', @typ = 2, @siz1 = 400, @siz2 = 1, @user = 9999999
	EXEC [dbo].[n_ColFAdd] @rel = @PostListModelId, @name = N'klucz', @typ = 2, @siz1 = 400, @siz2 = 1, @user = 9999999
	EXEC [dbo].[n_ColFAdd] @rel = @PostModelId, @name = N'klucz', @typ = 2, @siz1 = 400, @siz2 = 1, @user = 9999999
	EXEC [dbo].[n_ColFAdd] @rel = @ViewFactoryId, @name = N'typ', @typ = 2, @siz1 = 1000, @siz2 = 1, @user = 9999999
	EXEC [dbo].[n_ColFAdd] @rel = @PostListModelId, @name = N'typ', @typ = 2, @siz1 = 1000, @siz2 = 1, @user = 9999999
	EXEC [dbo].[n_ColFAdd] @rel = @PostModelId, @name = N'typ', @typ = 2, @siz1 = 1000, @siz2 = 1, @user = 9999999

	EXEC [dbo].[n_ColF1Add] @tab = @BlogSettingsId, @name = N'viewfactory', @rel = @ViewFactoryId, @user = 9999999
	EXEC [dbo].[n_ColF1Add] @tab = @BlogSettingsId, @name = N'postlistmodel', @rel = @PostListModelId, @user = 9999999
	EXEC [dbo].[n_ColF1Add] @tab = @BlogSettingsId, @name = N'postmodel', @rel = @PostModelId, @user = 9999999
	
	INSERT INTO bht_Columns (ColumnId, DisplayName, [Description], Sort)
    SELECT
        id, N'Fabryka widoku', N'', 600
    FROM
        n_Tree t
    WHERE
        parent = @BlogSettingsId
        AND name = N'viewfactory'
	
	INSERT INTO bht_Columns (ColumnId, DisplayName, [Description], Sort)
    SELECT
        id, N'Źródło danych dla listy postów', N'', 700
    FROM
        n_Tree t
    WHERE
        parent = @BlogSettingsId
        AND name = N'postlistmodel'

	INSERT INTO bht_Columns (ColumnId, DisplayName, [Description], Sort)
    SELECT
        id, N'Źródło danych dla listy postu', N'', 800
    FROM
        n_Tree t
    WHERE
        parent = @BlogSettingsId
        AND name = N'postmodel'


	INSERT INTO bht_GroupColumnsSplit (TabId, ColumnId)
	SELECT
		(SELECT 
			gt.TabId
		FROM 
			n_Tree t
			INNER JOIN bht_Columns c ON t.id = c.ColumnId
			INNER JOIN bht_GroupColumnsSplit gcs ON c.ColumnId = gcs.ColumnId
			INNER JOIN bht_GroupTabs gt ON gcs.TabId = gt.TabId
		WHERE 
			parent = @BlogSettingsId
			AND name = 'title'), id
	FROM
		n_Tree
	WHERE
		parent = @BlogSettingsId
		AND name IN ('viewfactory', 'postlistmodel', 'postmodel')

END
GO
EXEC bhp_Temp_ModStructure
GO
DROP PROCEDURE bhp_Temp_ModStructure
GO
INSERT INTO SYS_BLOG_VIEWFACTORIES (del, identyfikator, cuser, ctime, klucz, typ) VALUES (0, 'Standardowa biblioteka', 9999999, GETDATE(), 'standard', 'blackhouse.NemoBlog.Web.StandardBlogViewFactory, blackhouse.NemoBlog.Web')
GO
INSERT INTO SYS_BLOG_POSTLISTMODEL (del, identyfikator, cuser, ctime, klucz, typ) VALUES (0, 'Standardowa biblioteka', 9999999, GETDATE(), 'standard', 'blackhouse.NemoBlog.Business.Model.StandardPostListModel,blackhouse.NemoBlog.Business')
GO
INSERT INTO SYS_BLOG_POSTMODEL (del, identyfikator, cuser, ctime, klucz, typ) VALUES (0, 'Standardowa biblioteka', 9999999, GETDATE(), 'standard', 'blackhouse.NemoBlog.Business.Model.StandardPostModel,blackhouse.NemoBlog.Business')
